Solved: Escape an XML String in Flex

I was recently asked to troubleshoot some legacy code where an HTTPService call was (sometimes) failing on the server side due to malformed XML payload in a String parameter.  On the client side, the XML was being created as a String from user input, which opened the door for invalid characters to be injected directly into the markup.

Rather than refactor the process that generates the XML altogether, I set out to see if there was a simple approach to simply escape the special characters and keep the rest of the String intact. I started to explore functions like HTMLEncode, thinking I could find functionality similar to what I needed.

Ultimately, the solution was far simpler.

It turns out that casting an XML-formatted String to an instance of the XML class handles special characters and performs all of the necessary logic to escape any offenders. So by simply constructing an XML object from the source String, then calling toString() on the XML object, we can effectively sanitize the original String into valid markup that can be parsed as expected.

var result:String = XML(value).toString();

Nifty.

[Fixed] An internal build error has occurred

When working in Eclipse/Flash Builder, occasionally something wacky will happen in a project or the workspace itself that causes the following message to appear: "An internal build error has occurred. See the error log for more information." In some cases, a refresh and/or clean of the project in question is enough to straighten things out. But if that were always the case, this would be a very short blog entry, and that's not really my style.

I recently encountered the "internal build error" monster when working with a Flex module I hadn't touched in months. I simply opened it up and tried to build it, and I was instantly on my way to bang-my-head-against-my-desk-in-frustration territory. Nothing about the project had changed, so all signs pointed to something in the development environment. But what?

[More]

Hair-Trigger

I spent most of my morning chasing a sneaky little bug. Basically, once upon a time one of our tables contained a column (to protect the innocent, let's say it was called Meaningless_Data). Several months ago, my team removed the column from the DB schema as well as all references to it in the code.

I grabbed the changes and continued on my merry way... until today, which apparently is the first time I've tried to use a function that touches that particular table. I kept getting an error:

Type: Database
Message: Error Executing Database Query.
Detail: Invalid column name 'Meaningless_Data'.

So it's looking for the column and not finding it. Not surprising, since we deliberately deleted it a long time ago. I triple-checked the code, but couldn't find a single reference to Meaningless_Data in any SQL statement (or anywhere else in the codebase, for that matter).

I drove myself batty for way too long before copying the query straight from CFCATCH.SQL and manually running it against my local DB. Same error. Okay, it's not a Coldfusion issue...

Then I ran it against the DB on our development server. Worked like a charm. Getting warmer...

I generated SQL scripts for the table on each machine and diffed them, and the culprit was revealed. A trigger was pointing to the missing column, and was firing every time I touched the table. The other developer had updated the triggers on his local DB and the dev server, but when I grabbed the schema and code updates, I didn't think to look there.

File under lessons learned.

BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner